< previous page page_522 next page >

Page 522
0522-01.jpg
Figure 13.16.
Results of a foreign key constraint on unmatched column names.
It is also possible to create a multicolumn foreign key constraint. When you create multicolumn foreign key constraints, you must reference the same number of columns on each side of the relationship. For example, if you have a primary key index called PKBudgetCode that contains three columns, any foreign key constraint you define in another table that references PKBudgetCode must also contain three columns.
The example in Listing 13.15 shows an added foreign key constraint in the JobsTable. This constraint sets up a relationship between the Budget columns in the BudgetTrack table and JobsTable. Make the changes to the SQLVB04.SQV script and execute it to check for errors. See Figure 13.17 to compare your results.
Type.gifListing 13.15. Creating a multicolumn foreign key constraint.
// create a database
dbMake sqlvb04.mdb;
// create budget tracking file
CREATE TABLE BudgetTrack
   (BudgetPrefix TEXT(5),
    BudgetCode   TEXT(10),
    BudgetSuffix TEXT(5),
    CONSTRAINT PKBudgetCode PRIMARY KEY (BudgetPrefix,BudgetCode,BudgetSuffix),
    AnnBudgetAmt CURRENCY,
    YTDActualAmt CURRENCY
   );
// create jobs title table
CREATE TABLE JobsTable

 
< previous page page_522 next page >

If you like this book, buy it!